//
//  SISSAddCommentViewController.m
//  SISSAPP
//
//  Created by 优房网 on 2017/7/17.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSAddCoopCommentViewController.h"
#import "SISSRateBarView.h"
#import "SISSNetworkingManager+CoopProgress.h"
#import "SISSHouseCoopProgressModel.h"
#import "SISSHouseCoopTakeLookModel.h"

@interface SISSAddCoopCommentViewController ()<SISSRateBarViewDelegate>

/// 房屋信息真实度Label
@property (weak, nonatomic) UILabel *validityLabel;
/// 服务态度满意度Label
@property (weak, nonatomic) UILabel *satisfyLabel;
/// 业务水平专业度Label
@property (weak, nonatomic) UILabel *businessLevelLabel;
/// 房屋信息真实度StarView
@property (weak, nonatomic) SISSRateBarView *validityStarView;
/// 服务态度满意度StarView
@property (weak, nonatomic) SISSRateBarView *satisfyStarView;
/// 业务水平专业度StarView
@property (weak, nonatomic) SISSRateBarView *businessLevelStarView;

/// 评语Label
@property (weak, nonatomic) UILabel *commentLabel;
/// 评语TextView
@property (weak, nonatomic) UITextView *commentTextView;
/// 确定按钮
@property (weak, nonatomic) UIButton *confirmButton;

/// 房屋信息真实度星级
@property (assign, nonatomic) NSInteger validityStar;
/// 服务态度满意度星级
@property (assign, nonatomic) NSUInteger satisfyStar;
/// 业务水平专业度星级
@property (assign, nonatomic) NSInteger businessLevelStar;

@end

@implementation SISSAddCoopCommentViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"服务评价";
}

#pragma mark - SISSRateBarViewDelegate
- (void)rateBarViewDidSelectedRateBarView:(SISSRateBarView *)rateBarView atIndex:(NSInteger)index {
    rateBarView.rate = index;
    switch (rateBarView.tag) {
        case 100:
            self.validityStar = index;
            break;
            
        case 101:
            self.satisfyStar = index;
            break;
            
        case 102:
            self.businessLevelStar = index;
            break;
            
        default:
            break;
    }
}

#pragma mark - 确定按钮点击事件
- (void)confirmButtonClickAction {
    // takelook_type 线上线下
    // commentType 1：带看评价 2：服务评价
    // cooperationType 1：房源合作 2：客源合作
    NSLog(@" %zd %zd %zd \n%@",self.validityStar,self.satisfyStar,self.businessLevelStar,self.commentTextView.text);
    NSString *content = self.commentTextView.text;
    
    NSDictionary *parameter = @{
                                @"be_comment_sp_id":self.houseCoopProgressModel.sp_id,
                                @"atlrId":self.takeLookModel.ID,
                                @"acbId":self.houseCoopProgressModel.ID,
                                @"house_true_score":@(self.validityStar),
                                @"satisfaction_score":@(self.satisfyStar),
                                @"profession_score":@(self.businessLevelStar),
                                @"content":content,
                                @"takelook_type":@(self.takeLookModel.takeLookType),
                                @"comment_type":@(1),
                                @"cooperation_type":@(1)
                                };
    
    [kNetworkManager insertBrokerCommentBrokerWithParameters:parameter success:^(id responseObject) {
        
        [SISSTools showSVWithTitle:@"评论成功"];
        
    } failed:^(NSError *error) {
        
        NSLog(@"%@",error);
    }];
    
}

#pragma mark - UI
- (void)setupSubviews {
    [super setupSubviews];
    
    
    UILabel *validityLabel = [[UILabel alloc] init];
    validityLabel.font = [UIFont systemFontOfSize:16];
    validityLabel.textColor = MAIN_TEXT_COLOR;
    validityLabel.text = @"房屋信息真实度：";
    [self.view addSubview:validityLabel];
    self.validityLabel = validityLabel;
    
    SISSRateBarView *validityView = [[SISSRateBarView alloc] init];
    validityView.delegate = self;
    validityView.starTintColor = [UIColor redColor];
    validityView.tag = 100;
    [self.view addSubview:validityView];
    self.validityStarView = validityView;
    
    UILabel *satisfyLabel = [[UILabel alloc] init];
    satisfyLabel.font = [UIFont systemFontOfSize:16];
    satisfyLabel.textColor = MAIN_TEXT_COLOR;
    satisfyLabel.text = @"服务态度满意度：";
    [self.view addSubview:satisfyLabel];
    self.satisfyLabel = satisfyLabel;
    
    SISSRateBarView *satisfyStarView = [[SISSRateBarView alloc] init];
    satisfyStarView.delegate = self;
    satisfyStarView.starTintColor = [UIColor redColor];
    satisfyStarView.tag = 101;
    [self.view addSubview:satisfyStarView];
    self.satisfyStarView = satisfyStarView;
    
    UILabel *businessLevelLabel = [[UILabel alloc] init];
    businessLevelLabel.font = [UIFont systemFontOfSize:16];
    businessLevelLabel.textColor = MAIN_TEXT_COLOR;
    businessLevelLabel.text = @"业务水平专业度：";
    [self.view addSubview:businessLevelLabel];
    self.businessLevelLabel = businessLevelLabel;
    
    SISSRateBarView *businessLevelStarView = [[SISSRateBarView alloc] init];
    businessLevelStarView.delegate = self;
    businessLevelStarView.starTintColor = [UIColor redColor];
    businessLevelStarView.tag = 102;
    [self.view addSubview:businessLevelStarView];
    self.businessLevelStarView = businessLevelStarView;
    
    UILabel *commentLabel = [[UILabel alloc] init];
    commentLabel.font = [UIFont systemFontOfSize:16];
    commentLabel.textColor = MAIN_TEXT_COLOR;
    commentLabel.text = @"评语：";
    [self.view addSubview:commentLabel];
    self.commentLabel = commentLabel;
    
    UITextView *commentTextView = [[UITextView alloc] init];
    commentTextView.layer.borderWidth = 1;
    commentTextView.layer.borderColor = [UIColor groupTableViewBackgroundColor].CGColor;
    [self.view addSubview:commentTextView];
    self.commentTextView = commentTextView;
    
    
    UIButton *confirmButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [confirmButton setTitle:@"确定" forState:UIControlStateNormal];
    [confirmButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [confirmButton setBackgroundColor:MAIN_COLOR];
    [confirmButton addTarget:self action:@selector(confirmButtonClickAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:confirmButton];
    self.confirmButton = confirmButton;
}

#pragma mark - 约束
- (void)initConstraint {
    [super initConstraint];
    
    CGFloat margin = 8.0;
    WeakSelf
    [self.validityLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.view).offset(2 * margin);
        make.top.equalTo(weakSelf.view).offset(10 * margin);
    }];
    
    [self.validityStarView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.validityLabel.mas_right).offset(margin);
        make.centerY.equalTo(weakSelf.validityLabel);
        make.size.mas_equalTo(CGSizeMake(200, 30));
    }];
    
    [self.satisfyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.validityLabel);
        make.top.equalTo(weakSelf.validityLabel.mas_bottom).offset(margin);
    }];
    
    [self.satisfyStarView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.validityStarView);
        make.centerY.equalTo(weakSelf.satisfyLabel);
        make.size.equalTo(weakSelf.validityStarView);
    }];
    
    [self.businessLevelLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.satisfyLabel);
        make.top.equalTo(weakSelf.satisfyLabel.mas_bottom).offset(margin);
    }];
    
    [self.businessLevelStarView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.satisfyStarView);
        make.centerY.equalTo(weakSelf.businessLevelLabel);
        make.size.equalTo(weakSelf.satisfyStarView);
    }];
    
    [self.commentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.businessLevelLabel);
        make.top.equalTo(weakSelf.businessLevelLabel.mas_bottom).offset(4 * margin);
    }];
    
    [self.commentTextView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.commentLabel);
        make.top.equalTo(weakSelf.commentLabel.mas_bottom);
        make.right.equalTo(weakSelf.view).offset(-2 * margin);
        make.height.mas_equalTo(10 * margin);
    }];
    
    [self.confirmButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(weakSelf.view);
        make.height.mas_equalTo(6 * margin);
    }];
}

@end
